package com.viego.financialrecommendsystem.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.viego.financialrecommendsystem.entity.Article;
import com.viego.financialrecommendsystem.entity.Comment;
import com.viego.financialrecommendsystem.entity.Discuss;
import com.viego.financialrecommendsystem.mapper.CommentMapper;
import com.viego.financialrecommendsystem.mapper.DiscussMapper;
import com.viego.financialrecommendsystem.service.IDiscussService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class DiscussServiceImpl implements IDiscussService {

    @Resource
    DiscussMapper discussMapper;

    @Resource
    CommentMapper commentMapper;

    @Override
    public Discuss queryById(Long discussId) {
        return discussMapper.selectById(discussId);
    }

    @Override
    public List<Comment> comment(long parseLong) {
        LambdaQueryWrapper<Comment> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Comment::getDiscussId,parseLong);
        return commentMapper.selectList(queryWrapper);
    }

    @Override
    public Integer collect(Long discussId) {
        return discussMapper.collect(discussId);
    }


    @Override
    public boolean saveComment(Comment comment) {
        return commentMapper.insert(comment) == 1;
    }


    @Override
    public boolean addCollect(String userId, String discussId) {
        return discussMapper.addCollect(userId,discussId) == 1;
    }

    @Override
    public boolean isCollected(long userId, long discussId) {
        Integer collected = discussMapper.isCollected(userId, discussId);
        if (collected == null){
            return false;
        }else{
            return true;
        }
    }

    @Override
    public List<Discuss> article(long parseLong) {
        LambdaQueryWrapper<Discuss> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Discuss::getCreateBy,parseLong);
        return discussMapper.selectList(queryWrapper);
    }

    @Override
    public boolean save(Discuss discuss) {
        return discussMapper.insert(discuss) == 1;
    }

    @Override
    public List<String> type() {
        return discussMapper.type();
    }

    @Override
    public boolean removeCollect(long userId, long discussId) {
        return discussMapper.removeCollect(userId,discussId) == 1;
    }
}
